package com.ideabove.heart;



import com.ideabove.heart.manager.AppManager;
import com.ideabove.heart.manager.MoeManager;
import com.ideabove.heart.manager.ScheduleManager;
import com.ideabove.heart.util.MyUtil;

import android.media.MediaPlayer;
import android.media.AudioManager;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;

public class MoeIntroActivity extends MyActivity {
	Activity mActivity;
	MediaPlayer mplayer = new MediaPlayer();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.intro_moe);
		mActivity = this;

		// DEfault dress setting....
		ScheduleManager.setDefaultDress(MoeIntroActivity.this, "dress_training.png", "hair_normal.png");	
		
		final TextView textView = (TextView)findViewById(R.id.main_calling_txt);
		MyUtil.blinkText(textView, 700);
		
		Uri alert =  RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
		try{
			mplayer.setDataSource(this, alert);
			final AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
			audio.setStreamVolume(
					AudioManager.STREAM_RING, 
					(int)(audio.getStreamMaxVolume(AudioManager.STREAM_RING)*0.50), // 90% 볼륨 다틀려 Max 값이 기기마다 
					AudioManager.FLAG_PLAY_SOUND);
	
			mplayer.setAudioStreamType(AudioManager.STREAM_RING);		
			mplayer.prepare();
			mplayer.start();
		}catch(Exception e){
			e.printStackTrace();
		}
		
		final ImageView image = (ImageView)findViewById(R.id.hang_up_btn);
		image.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub								
				mplayer.stop();
				
				// 에피소드 1에 스텝 1을 수행했다.
				ScheduleManager sm = new ScheduleManager(MoeIntroActivity.this);
				sm.episodeStart();
				
				
				MoeManager.setWhatWillIdo(MoeManager.DO_INTRO);
				Intent intent = new Intent(MoeIntroActivity.this, MoeActivity.class);
				mActivity.startActivity(intent);
				finish();	
			}
		});
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub		
		AppManager.pause(MoeIntroActivity.this);
		mplayer.stop();
		super.onDestroy();
	}


	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onStart();
		AppManager.pause(MoeIntroActivity.this);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		AppManager.pause(MoeIntroActivity.this);		
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		finish();
	}
	
	
	
}
